# -*- coding:utf-8 -*-
#! python3
from facecat import *

#绘制视图
#view:视图
#paint:绘图对象
#clipRect:区域
def onPaint(view, paint, clipRect):
	if view.viewType == "tabbutton":
		if view.parent.viewName == "TabView":
			tSize = paint.textSize(view.text, view.font)
			paint.fillRect(view.backColor, 0, 0, view.size.cx, view.size.cy)
			paint.drawRect(view.borderColor, 1, 0, 0, 0, view.size.cx, view.size.cy)
			paint.drawText(view.text, view.textColor, view.font, 5, (view.size.cy - tSize.cy) / 2)
			#绘制关闭按钮
			tR = 6
			paint.drawLine(view.textColor, 2, 0, view.size.cx - tR * 2.5, view.size.cy / 2 - tR, view.size.cx - tR * 0.5, view.size.cy / 2 + tR)
			paint.drawLine(view.textColor, 2, 0, view.size.cx - tR * 2.5, view.size.cy / 2 + tR, view.size.cx - tR * 0.5, view.size.cy / 2 - tR)
			return
	onPaintDefault(view, paint, clipRect)

#视图的鼠标点击方法
#view 视图
#firstTouch:是否第一次触摸 
#firstPoint:第一次触摸的坐标 
#secondTouch:是否第二次触摸 
#secondPoint:第二次触摸的坐标
#clicks 点击次数
def onClick(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks):
	if view.viewType == "tabbutton":
		if view.parent.viewName == "TabView":
			tR = 6
			if firstPoint.x > view.size.cx - tR * 2.5:
				removeTabPage(view.parent, view)
				invalidateView(view.parent)
				return
	onClickDefault(view, firstTouch, firstPoint, secondTouch, secondPoint, clicks)

gPaint = FCPaint() #创建绘图对象
gPaint.onPaint = onPaint 
gPaint.onClick = onClick

#消息循环
def WndProc(hwnd,msg,wParam,lParam):
	return WndProcDefault(gPaint,hwnd,msg,wParam,lParam)

#初始化窗体
createMainWindow(gPaint, "facecat-py", WndProc)
current_file_path = os.path.abspath(__file__)
current_file_dir = os.path.dirname(current_file_path)
file0 = open(current_file_dir + "\\xml\\tabviewexample.xml", encoding="UTF-8")
xml = file0.read()
file0.close()
renderFaceCat(gPaint, xml)
showWindow(gPaint)